{-# LANGUAGE OverloadedStrings, ScopedTypeVariables, TypeSynonymInstances #-}

module Handler.Types where

import Yesod

import Data.Text           ( pack, unpack )
import Data.Text.Read      ( rational )


type Ra   = Double
type Dec  = Double
type Mag  = Double
type Deg  = Double
type Ang  = Double
type Zoom = Double


data Star = Star { ra  :: Ra 
                 , dec :: Dec 
                 , mag :: Mag
                 } deriving (Show, Eq)


data Instrument = VUVES
                | UVES
                | LSS
                | ISSIS
                deriving (Show,Read,Eq)

instance SinglePiece Double where
    fromSinglePiece s = case  rational s of
                            Right (i, _) -> Just i
                            Left _       -> Nothing
    toSinglePiece = pack.show

instance SinglePiece Instrument where
    fromSinglePiece s = case  (reads $ unpack s) of
                            (i, _):_ -> Just i
                            _        -> Nothing
    toSinglePiece = pack.show